package guoanmaker.operator.business.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.OperatorCommonServiceDownNew;
import guoanmaker.operator.business.model.OperatorCommonServiceNew;
import guoanmaker.operator.business.model.OperatorCommonServiceNewRound;
import guoanmaker.operator.business.model.OperatorCompanyDevelopServer;
import guoanmaker.operator.business.model.OperatorCompanyServiceDownNew;
import guoanmaker.operator.business.model.OperatorCompanyServiceNew;
import guoanmaker.operator.business.model.OperatorCompanyServiceNewRound;
import guoanmaker.operator.business.model.OperatorEventDetails;
import guoanmaker.operator.business.model.OperatorFinancingServiceNew;
import guoanmaker.operator.business.model.OperatorFinancingServiceNewRound;
import guoanmaker.operator.business.model.OperatorHotBusiness;
import guoanmaker.operator.business.model.OperatorHotBusinessNewForAPP;
import guoanmaker.operator.business.model.OperatorHotServerPc;
import guoanmaker.operator.business.model.OperatorHotwords;
import guoanmaker.operator.business.model.OperatorLeaseSpaceNew;
import guoanmaker.operator.business.model.OperatorOfficeSpace;
import guoanmaker.operator.business.model.OperatorPcActive;
import guoanmaker.operator.business.model.OperatorPcCompanyDevelop;
import guoanmaker.operator.business.model.OperatorRoundPhoto;
import guoanmaker.operator.business.model.OperatorServerClass;
import guoanmaker.operator.business.repository.OperatorCommonServiceDownNewRepository;
import guoanmaker.operator.business.repository.OperatorCommonServiceNewRepository;
import guoanmaker.operator.business.repository.OperatorCompanyDevelopServerRepository;
import guoanmaker.operator.business.repository.OperatorCompanyServiceDownNewRepository;
import guoanmaker.operator.business.repository.OperatorCompanyServiceNewRepository;
import guoanmaker.operator.business.repository.OperatorEventDetailsRepository;
import guoanmaker.operator.business.repository.OperatorFinancingServiceDownNewRepository;
import guoanmaker.operator.business.repository.OperatorFinancingServiceNewRepository;
import guoanmaker.operator.business.repository.OperatorHotBusinessNewForAPPRepository;
import guoanmaker.operator.business.repository.OperatorHotBusinessRepository;
import guoanmaker.operator.business.repository.OperatorHotServerPcRepository;
import guoanmaker.operator.business.repository.OperatorHotwordsRepository;
import guoanmaker.operator.business.repository.OperatorLeaseSpaceNewRepository;
import guoanmaker.operator.business.repository.OperatorOfficeSpaceRepository;
import guoanmaker.operator.business.repository.OperatorPcActiveRepository;
import guoanmaker.operator.business.repository.OperatorPcCompanyDevelopRepository;
import guoanmaker.operator.business.repository.OperatorRoundPhotoRepository;
import guoanmaker.operator.business.repository.OperatorServerClassRepository;

@Service
public class OperatorGroundPcService implements OperatorGroundPcServiceInterface {
	@Autowired
	 private  OperatorRoundPhotoRepository operatorRoundPhotoRepository;
	@Autowired
	private OperatorHotBusinessRepository operatorHotBusinessRepository;
	@Autowired
	private  OperatorHotwordsRepository operatorHotwordsRepository;
	@Autowired
	private OperatorPcActiveRepository operatorPcActiveRepository;
	@Autowired
	private OperatorEventDetailsRepository operatorEventDetailsRepository;
	@Autowired
	private OperatorCompanyDevelopServerRepository operatorCompanyDevelopServerRepository;
	@Autowired
	private OperatorPcCompanyDevelopRepository operatorPcCompanyDevelopRepository;
	@Autowired
	private OperatorServerClassRepository operatorServerClassRepository;
	@Autowired
	private OperatorOfficeSpaceRepository oeratorOfficeSpaceRepository;
	@Autowired
	private OperatorCommonServiceNewRepository operatorCommonServiceNewRepository;
	@Autowired
	private OperatorCommonServiceDownNewRepository operatorCommonServiceDownNewRepository;
	@Autowired
	private OperatorLeaseSpaceNewRepository operatorLeaseSpaceNewRepository;
	@Autowired
	private OperatorCompanyServiceNewRepository operatorCompanyServiceNewRepository;
	@Autowired
	private OperatorCompanyServiceDownNewRepository operatorCompanyServiceDownNewRepository;
	@Autowired
	private OperatorFinancingServiceNewRepository operatorFinancingServiceNewRepository;
	@Autowired
	private OperatorFinancingServiceDownNewRepository operatorFinancingServiceDownNewRepository;
	@Autowired
	private OperatorHotBusinessNewForAPPRepository operatorHotBusinessNewForPCRepository;
	@Autowired
	private OperatorHotServerPcRepository operatorHotServerPcRepository;
	@Override
	public Map selectgroundPc(String cityCode) {
		Map<String, Object> reMap = new HashMap<>();
		List<OperatorRoundPhoto>  rpspps=operatorRoundPhotoRepository.findBycityCode(cityCode);
		reMap.put("rpspps", rpspps);
		List<OperatorHotBusiness> ops=operatorHotBusinessRepository.getOperatorHotBusiness(cityCode);
		reMap.put("ops", ops);
		OperatorHotwords hot=operatorHotwordsRepository.findPcByCityCodeOne(cityCode);
		 List<OperatorHotwords> hots= operatorHotwordsRepository.findPcByCityCodetwo(cityCode);
		 reMap.put("hot", hot);
		 reMap.put("hots", hots);
		 List<OperatorPcActive> ocactives=operatorPcActiveRepository.getOperatorPcActive(cityCode);
			if(ocactives.size()>0){
				for(OperatorPcActive ocs:ocactives){
					OperatorEventDetails operatorEventDetails=operatorEventDetailsRepository.getSelectEventByid(ocs.getActiveId());
					if(null==operatorEventDetails){
						ocs.setActiveId("");
					}
				}
			}
			reMap.put("ocactives", ocactives);
			
			List<OperatorPcCompanyDevelop> opds=operatorPcCompanyDevelopRepository.getOperatorPcCompanyDevelops(cityCode);
			for(OperatorPcCompanyDevelop opd:opds){
				OperatorCompanyDevelopServer[] depservers=operatorCompanyDevelopServerRepository.getOperatorCompanyDevelopServers(opd.getId());
				opd.setOperatorCompanyDevelopServers(depservers);
			}
			List<OperatorServerClass> serverTwos=operatorServerClassRepository.selectByTwoServerclass();
			List<OperatorServerClass> serverThrees=operatorServerClassRepository.selectByThreeServerclass();
			reMap.put("opds", opds);
			reMap.put("serverTwos", serverTwos);
			reMap.put("serverThrees", serverThrees);
			List<OperatorOfficeSpace> opspace =oeratorOfficeSpaceRepository.getOperatorOfficeSpace(cityCode);
			reMap.put("opspace", opspace);
			//----------------------------------------------------------------------
			//2017 12 月底 新版运营后台配置返回数据
			//----------------------------------------------------------------------
			
			//常用服务返回数据
			List<OperatorCommonServiceNewRound> operatorCommonServiceNewRounds = new ArrayList<>();
			List<OperatorCommonServiceNew> operatorCommonServiceNews = operatorCommonServiceNewRepository.selectCommonServiceBycityCode(cityCode);//commonServiceQuery.getResultList();
			
			for (OperatorCommonServiceNew operatorCommonServiceNew : operatorCommonServiceNews) {
				List<OperatorCommonServiceDownNew> operatorCommonServiceDownNews = operatorCommonServiceDownNewRepository.findCommonServiceDownByCommonServiceNewId(operatorCommonServiceNew.getId());
				OperatorCommonServiceNewRound operatorCommonServiceNewRound= new OperatorCommonServiceNewRound();
				operatorCommonServiceNewRound.setOperatorCommonServiceNew(operatorCommonServiceNew);
				operatorCommonServiceNewRound.setOperatorCommonServiceDownNew(operatorCommonServiceDownNews);
				operatorCommonServiceNewRounds.add(operatorCommonServiceNewRound);
				
			}
			reMap.put("commonServiceNewRounds", operatorCommonServiceNewRounds);
			
			//租赁空间返回数据
			List<OperatorLeaseSpaceNew> leaseSpaceNews= operatorLeaseSpaceNewRepository.findOperatorLeaseSpaceNewByCityCode(cityCode);
			reMap.put("leaseSpaceNews", leaseSpaceNews);
			
			//企业服务返回数据
			List<OperatorCompanyServiceNewRound> operatorCompanyServiceNewRounds = new ArrayList<>();
			OperatorCompanyServiceNewRound companyServiceNewRound = null;
			List<OperatorCompanyServiceNew> companyServiceNews = operatorCompanyServiceNewRepository.findOperatorCompanyServiceNewByCityCode(cityCode);
			for (OperatorCompanyServiceNew operatorCompanyServiceNew : companyServiceNews) {
				companyServiceNewRound = new OperatorCompanyServiceNewRound();
				companyServiceNewRound.setOperatorCompanyServiceNew(operatorCompanyServiceNew);
				companyServiceNewRound.setOperatorCompanyServiceDownNews(operatorCompanyServiceDownNewRepository.findCompanyServiceDownNewByCompanyServiceId(operatorCompanyServiceNew.getId()));
				operatorCompanyServiceNewRounds.add(companyServiceNewRound);
			}
			reMap.put("companyServiceNewRounds", operatorCompanyServiceNewRounds);
			
			//热门服务
			List<OperatorHotServerPc> servers = operatorHotServerPcRepository.findBycityCode(cityCode);
			reMap.put("hotServerPc", servers);
			
			//投融资服务-推荐标的			
			OperatorFinancingServiceNewRound financingServiceProject = new OperatorFinancingServiceNewRound();
			List<OperatorFinancingServiceNew> operatorFinancingServiceNewsProject = operatorFinancingServiceNewRepository.findByCitycodeAndFinancingName(cityCode, "推荐标的");
			if (operatorFinancingServiceNewsProject != null && operatorFinancingServiceNewsProject.size() >0) {
				OperatorFinancingServiceNew operatorFinancingServiceNewProject = operatorFinancingServiceNewsProject.get(0);
				financingServiceProject.setOperatorFinancingServiceNew(operatorFinancingServiceNewProject);
				financingServiceProject.setOperatorFinancingServiceDownNews(operatorFinancingServiceDownNewRepository.findByFinancialServiceId(operatorFinancingServiceNewProject.getId()));
				
			}
			reMap.put("financingServiceProject", financingServiceProject);
			
			//投融资服务-金融大咖
			OperatorFinancingServiceNewRound financingServicePersonal = new OperatorFinancingServiceNewRound();
			List<OperatorFinancingServiceNew> operatorFinancingServicePersonal = operatorFinancingServiceNewRepository.findByCitycodeAndFinancingName(cityCode, "金融大咖");
			if (operatorFinancingServicePersonal != null && operatorFinancingServicePersonal.size() >0) {
				OperatorFinancingServiceNew operatorFoperatorFinancingServicePersonal = operatorFinancingServicePersonal.get(0);
				financingServicePersonal.setOperatorFinancingServiceNew(operatorFoperatorFinancingServicePersonal);
				financingServicePersonal.setOperatorFinancingServiceDownNews(operatorFinancingServiceDownNewRepository.findByFinancialServiceId(operatorFoperatorFinancingServicePersonal.getId()));
				
				
			}
			reMap.put("financingServicePersonal", financingServicePersonal);
			//热门商户
			List<OperatorHotBusiness> hotBusinesses = operatorHotBusinessRepository.getOperatorHotBusiness(cityCode);
			reMap.put("hotBusinesses", hotBusinesses);
			/*OperatorFinancingServiceNewRound operatorFinancingServiceNewRound = new OperatorFinancingServiceNewRound();
			List<OperatorFinancingServiceNew> operatorFinancingServiceNews = operatorFinancingServiceNewRepository.findByCitycodeAndFinancingName(cityCode, "金融大咖");
			OperatorFinancingServiceNew operatorFinancingServiceNew = operatorFinancingServiceNews.get(0);
			operatorFinancingServiceNewRound.setOperatorFinancingServiceNew(operatorFinancingServiceNew);
			operatorFinancingServiceNewRound.setOperatorFinancingServiceDownNews(operatorFinancingServiceDownNewRepository.findByFinancialServiceId(operatorFinancingServiceNew.getId()));
			*/
			
			/*OperatorFinancingServiceNewRound operatorFinancingServiceNewRound = new OperatorFinancingServiceNewRound();
			List<OperatorFinancingServiceNew> financingServiceNews= operatorFinancingServiceNewRepository.findFinancingServiceNewByCityCode(cityCode);
			for (OperatorFinancingServiceNew operatorFinancingServiceNew : financingServiceNews) {
				operatorFinancingServiceNewRound.setOperatorFinancingServiceDownNews(operatorFinancingServiceDownNewRepository.findFinancingServiceDownNewByFinancialServiceId(operatorFinancingServiceNew.getId()));
			}*/
		//	operatorFinancingServiceNewRound.setOperatorFinancingServiceNews(financingServiceNews);
			
		//	reMap.put("operatorFinancingServiceNewRound", operatorFinancingServiceNewRound);
			
			//热门服务商
		/*	List<OperatorHotBusinessNewForAPP> businessNewForPCs = operatorHotBusinessNewForPCRepository.findOperatorHotBusinessNewByCityCode(cityCode);
		//	List<OperatorHotBusinessNew> businessNews = operatorHotBusinessNewRepository.findOperatorHotBusinessNewByCityCode(cityCode);
			reMap.put("businessNewForPCs", businessNewForPCs);*/
			return reMap;
	}

}
